Method for managing flash memory module and associated flash memory controller and electronic device

ABSTRACT

The present invention provides a method for managing a flash memory module, wherein the flash memory module includes a plurality of blocks, and the method includes the steps of: building a garbage collection look-up table, wherein the garbage collection look-up table records a plurality of sets of importance information respectively corresponding to the plurality of blocks, and each set of importance information is used to represent a priority of performing a garbage collection operation on a corresponding block; and when performing the garbage collection operation is required, referring to the garbage collection look-up table to select a specific block that has a top priority of the garbage collection operation, and performing the garbage collection operation starting from the specific block.

BACKGROUND OF THE INVENTION 1. Field of the Invention

The present invention is related to flash memory, and more particularly,to a method for managing flash memory module and associated flash memorycontroller and electronic device.

2. Description of the Prior Art

In a conventional flash memory controller, when there are many blockshaving a need of being treated with a garbage collection operation in ashort time, the flash memory controller may sequentially perform thegarbage collection operation on the blocks according to a defaultpriority, for example, performing the garbage collection operation onblocks having a need of wear-leveling first, and so on. However, whenperforming the garbage collection operation on each block is required,there may be many factors to be considered. In addition towear-leveling, the factors may comprise read reclaim or read refresh aswell. Thus, when the order of performing the garbage collectionoperation on the blocks is determined simply according to the defaultpriority in the related art, the actual needs of the blocks cannot beproperly considered. In general, it is impossible to complete thegarbage collection operation of all blocks having such need at once.Thus, the way of the related art may probably make a portion of blockshaving lower default priority unable to be treated with the garbagecollection operation, and may thereby cause data loss.

SUMMARY OF THE INVENTION

It is therefore an objective of the present invention to design a methodfor managing flash memory module, which records a priority of a garbagecollection operation of each block through building a garbage collectionlook-up table, to be a reference for a flash memory controller whileperforming the garbage collection operation, in order to solve therelated art problems.

In an embodiment of the present invention, a method for managing a flashmemory module is disclosed, wherein the flash memory module comprises aplurality of blocks, and the method comprises: building a garbagecollection look-up table, wherein the garbage collection look-up tablerecords a plurality of sets of importance information respectivelycorresponding to the plurality of blocks, and each set of importanceinformation is used to represent a priority of performing a garbagecollection operation on a corresponding block; and when performing thegarbage collection operation of the flash memory module is required,referring to the garbage collection look-up table to select a specificblock that has a top priority of the garbage collection operation, andperforming the garbage collection operation starting from the specificblock.

In another embodiment of the present invention, a flash memorycontroller is disclosed, wherein the flash memory controller is arrangedto access a flash memory module, the flash memory module comprises aplurality of blocks, and the flash memory controller comprises a readonly memory that is arranged to store a program code and amicroprocessor that is arranged to execute the program code to controlaccess to the flash memory module. In operations of the flash memorycontroller, the microprocessor builds a garbage collection look-uptable, wherein the garbage collection look-up table records a pluralityof sets of importance information respectively corresponding to theplurality of blocks, and each set of importance information is used torepresent a priority of performing a garbage collection operation on acorresponding block; and when performing the garbage collectionoperation of the flash memory module is required, the microprocessorrefers to the garbage collection look-up table to select a specificblock that has a top priority of the garbage collection operation, andperforms the garbage collection operation starting from the specificblock.

In another embodiment of the present invention, an electronic device isdisclosed, which comprises a flash memory module that comprises aplurality of blocks and a flash memory controller that is arranged toaccess the flash memory module. In operations of the electronic device,the flash memory controller builds a garbage collection look-up table,wherein the garbage collection look-up table records a plurality of setsof importance information respectively corresponding to the plurality ofblocks, and each set of importance information is used to represent apriority of performing a garbage collection operation on a correspondingblock; and when performing the garbage collection operation is required,the flash memory controller refers to the garbage collection look-uptable to select a specific block that has a top priority of the garbagecollection operation, and performs the garbage collection operationstarting from the specific block.

These and other objectives of the present invention will no doubt becomeobvious to those of ordinary skill in the art after reading thefollowing detailed description of the preferred embodiment that isillustrated in the various figures and drawings.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a diagram illustrating a memory device according to anembodiment of the present invention.

FIG. 2 is a diagram illustrating a wear-leveling requirement data tableaccording to an embodiment of the present invention.

FIG. 3 is a diagram illustrating a read reclaim requirement data tableaccording to an embodiment of the present invention.

FIG. 4 is a diagram illustrating a read refresh requirement data tableaccording to an embodiment of the present invention.

FIG. 5 is a diagram illustrating a garbage collection look-up tableaccording to an embodiment of the present invention.

FIG. 6 is a flowchart illustrating the method for managing a flashmemory module according to an embodiment of the present invention.

DETAILED DESCRIPTION

FIG. 1 is a diagram illustrating a memory device 100 according to anembodiment of the present invention. The memory device 100 comprises aflash memory module 120 and a flash memory controller 110, and the flashmemory controller 110 is arranged to access the flash memory module 120.According to this embodiment, the flash memory controller 110 comprisesa microprocessor 112, a read only memory (ROM) 112M, a control logic114, a buffer memory 116, and an interface logic 118. The ROM 112M isarranged to store a program code 112C, and the microprocessor 112 isarranged to execute the program code 112C to control access to the flashmemory module 120. The control logic 114 comprises an encoder 132 and adecoder 134, where the encoder 132 is arranged to encode data that iswritten into the flash memory module 120 to generate corresponding checkcode (which may be referred to as error correction code (ECC)), and thedecoder 134 is arranged to decode data that is read from the flashmemory module 120.

Typically, the flash memory module 120 comprises a plurality of flashmemory chips and each flash memory chip comprises a plurality of blocks,and the flash memory controller 110 performs data erasing operations onthe flash memory module 120 in unit of block. In addition, a block mayrecord a specific number of data pages, where the flash memorycontroller 110 performs data writing operations on the flash memorymodule 120 in unit of data page. In this embodiment, the flash memorycontroller 120 is a 3D NAND-type flash memory module.

In practice, the flash memory controller 110 executing the program code112C through the microprocessor 112 may utilize internal componentswithin the flash memory controller 110 to perform various controloperations, for example, utilizing the control logic 114 to controlaccess operations of the flash memory module 120 (more particularly, theaccess operations to at least one block or at least one data page),utilizing the buffer memory 116 to perform required buffer processing,and utilizing the interface logic 118 to communicate with a host device130. The buffer memory 116 is implemented by a random access memory(RAM). For example, the buffer memory 116 may be a static RAM (SRAM),but the present invention is not limited thereto.

In an embodiment, the memory device 100 may be a portable memory device(e.g. a memory card conforming to SD/MMC, CF, MS or XD specification),and the host device 130 is an electronic device that is capable ofconnecting with memory devices, such as any of a mobile phone, a laptopcomputer, a desktop computer, and so on. In another embodiment, thememory device 100 may be a solid-state drive (SSD) or an embeddedstorage device conforming to universal flash storage (UFS) or embeddedmulti media card (EMMC) specifications, to be installed in an electronicdevice, such as the mobile phone, the laptop computer, or the desktopcomputer, where the host device 130 may be a processor of the electronicdevice.

In a process of the flash memory controller 110 reading the flash memorymodule 120, the flash memory controller 110 may build or refresh awear-leveling requirement data table, a read reclaim requirement datatable and a read refresh requirement data table. FIG. 2 is a diagramillustrating a wear-leveling requirement data table 200 according to anembodiment of the present invention. Referring to FIG. 2, assuming thatthere are a plurality of blocks B1, B2, B3 . . . in the flash memorymodule 120, the wear-leveling requirement data table 200 may record oneor more blocks (within the plurality of blocks), each having an erasecount (e.g. a number of times that a block has been erased) greater thana first threshold, and may record erase counts thereof, where the erasecount indicates a total erase count that is counted starting from a timepoint when the flash memory controller 110 starts operating after it isconnected with the flash memory module 120. For example, assuming thatthe first threshold is 60, as erase counts of the blocks B9, B6, B1 andB7 are 86, 62, 95 and 63, respectively, which are greater than 60, theblocks B9, B6, B1, B7 and the erase counts thereof may be recorded inthe wear-leveling requirement data table 200. As erase counts of therest of the blocks are not greater than 60 times, or the rest of theblocks belong to blank blocks, the rest of the blocks are not recordedin the wear-leveling requirement data table 200.

FIG. 3 is a diagram illustrating a read reclaim requirement data table300 according to an embodiment of the present invention. Referring toFIG. 3, assuming that there are the plurality of blocks B1, B2, B3 . . .in the flash memory module 120 as shown in FIG. 2, the read reclaimrequirement data table 300 may record one or more blocks (within theplurality of blocks), each having a bit error count greater than asecond threshold, and may record error bit counts thereof. For example,assuming that the second threshold is 50, as bit error counts of theblocks B3, B9, B2, B5 and B1 are 56, 58, 65, 68 and 52, respectively,which are greater than 50, the blocks B3, B9, B2, B5, B1 and the biterror counts thereof may be recorded in the read reclaim requirementdata table 300. In this embodiment, the read claim requirement datatable 300 is a queue, and the aforementioned bit error count is obtainedby decoding after the flash memory controller 110 reads a sector or achunk of any data page within a block. That is, during reading a block,when detecting that a bit error count of a decoded sector or chunk isgreater than 50, the flash memory controller 110 may add the block intothe read reclaim requirement data table 300.

FIG. 4 is a diagram illustrating a read refresh requirement data table400 according to an embodiment of the present invention. Referring toFIG. 4, assuming that there are the plurality of blocks B1, B2, B3 . . .in the flash memory module 120 as shown in FIG. 2, the read refreshrequirement data table 400 may record one or more blocks (within theplurality of blocks), each having a read count (e.g. a number of timesthat a block has been read) greater than a third threshold, and mayrecord read counts thereof. For example, assuming that the thirdthreshold is 8000, as read counts of the blocks B1, B4 and B3 are 8012,8045 and 11210, respectively, which are greater than 8000, the blocksB1, B4, B3 and the read counts thereof may be recorded in the readrefresh requirement data table 400. In this embodiment, only queue partis illustrated in the read refresh requirement data table 400, and inpractice, the read refresh requirement data table 400 may also comprisea record table that records the read count of each block. When the flashmemory controller 110 sends a read command to ask for reading data of ablock within the blocks, the read count of the block may increase withan increment of one, and when contents or data of the block are erasedand re-written data therein, the read count recorded in the record tablemay be reset for restarting counting.

In this embodiment, the aforementioned wear-leveling requirement datatable 200, read reclaim requirement data table 300 and read refreshrequirement data table 400 are kept being refreshed in the fresh memorymodule 120 during a process of the flash memory controller 110 accessingthe flash memory module 120, and may be temporarily stored in the buffermemory 116.

In this embodiment, the flash memory controller 110 may build a garbagecollection look-up table according to the contents or data of theaforementioned wear-leveling requirement data table 200, read reclaimrequirement data table 300 and read refresh requirement data table 400,where the garbage collection look-up table records a plurality of setsof importance information respectively corresponding to the plurality ofblocks, and each set of importance information is used to represent apriority of performing a garbage collection operation on a correspondingblock. Please refer to FIG. 5, which is a diagram illustrating a garbagecollection look-up table 500 according to an embodiment of the presentinvention. As shown in FIG. 5, the garbage collection look-up table 500may record a set of importance information of each of the blocks B1, B2,B3 . . . , where the set of importance information is obtained bycalculating information of the aforementioned each block in thewear-leveling requirement data table 200, the read reclaim requirementdata table 300 and the read refresh requirement data table 400. Moreparticularly, in this embodiment, it is assumed that the importance ofwear-leveling requirement is greater than that of read reclaimrequirement and the importance of read reclaim requirement is greaterthan that of read refresh requirement, and thus, weightings of thewear-leveling requirement, the read reclaim requirement and the readrefresh requirement are assumed to be 4, 2 and 1, respectively. Thus,taking the block B1 as an example, since the block B1 is recorded in allof the wear-leveling requirement data table 200, the read reclaimrequirement data table 300 and the read refresh requirement data table400 (i.e. the block B1 has the wear-leveling requirement, the readreclaim requirement and the read refresh requirement, concurrently), aset of importance information of the block B1 may be calculated asfollows: 4*1+2*1+1*1=7. In addition, taking the block B3 as an example,since the block B3 is only recorded in the read reclaim requirement datatable 300 and the read refresh requirement data table 400 (i.e. theblock B3 only has the read reclaim requirement and the read refreshrequirement), a set of importance information of the block B3 may becalculated as follows: 4*0+2*1+1*1=3. As mentioned above, since the setof importance information of the aforementioned each block is calculatedby referring to each of the wear-leveling requirement, the read reclaimrequirement and the read refresh requirement, the priority of thegarbage collection of the aforementioned each block can be indeedreflected. That is, as shown in FIG. 5, a greater value of the set ofimportance information indicates a higher priority of the garbagecollection operation.

In this embodiment, when respective sets of importance information oftwo blocks are the same, for example, the sets of importance informationof B6 and B7 are both “4”, re-referring to the contents or data of thewear-leveling requirement data table 200, the read reclaim requirementdata table 300 and/or the read refresh requirement data table 400 todetermine priorities thereof is needed. For example, since thewear-leveling requirement data table 200 records that the erase count ofthe block B7 is greater than the erase count of the block B6, the flashmemory controller 110 may determine that the priority of the garbagecollection operation of the block B7 is greater than the priority of thegarbage collection operation of the block B6.

In this embodiment, when the garbage collection operation of the flashmemory module 120 is required, the flash memory controller 110 maysequentially perform the garbage collection operation on the blocks B1,B9, B7, B6, B3, B5, B2 and B4 according to the sets of importanceinformation recorded by the garbage collection look-up table 500. Thatis, the flash memory controller 110 may move valid data within theblocks B1, B9, B7, B6, B3, B5, B2 and B4 into other blocks such as blankblocks, and erase a block (e.g. any of the blocks B1, B9, B7, B6, B3,B5, B2 and B4) or label this block as invalid after all valid datawithin this block have been moved.

As mentioned above, since the set of importance information of theaforementioned each block is calculated by referring to each of thewear-leveling requirement, the read reclaim requirement and the readrefresh requirement, a block having greater importance information (e.g.a greater value of importance information) usually has two or morerequirements, concurrently. Thus, preferentially performing the garbagecollection operation on the block having greater importance informationcan complete two or more requirements, concurrently, where theperformance of the flash memory controller 110 can be improved. TakingFIG. 5 as an example, since the block B1 having the greatest importanceinformation (e.g. the greater value of importance information) has thewear-leveling requirement, the read reclaim requirement and the readrefresh requirement, concurrently, preferentially performing the garbagecollection operation on the block B1 can complete these threerequirements, concurrently, and space of the read reclaim requirementdata table 300 and the read refresh requirement data table 400 can bequickly released to prevent the condition of queue overflow.

In another embodiment of the present invention, the garbage collectionlook-up table 500 may just be built according to two of thewear-leveling requirement data table 200, the read reclaim requirementdata table 300 and the read refresh requirement data table 400. That is,the garbage collection look-up table 500 may just reflect thewear-leveling requirement and the read reclaim requirement of eachblock, or just reflect the wear-leveling requirement and the readrefresh requirement of each block, or just reflect the read reclaimrequirement and the read refresh requirement of each block. Thesealterations on design should be included in the scope of the presentinvention.

It should be noted that, the garbage collection look-up table 500 shownin FIG. 5 is an example for descriptive purpose only, and is not meantto be a limitation of the present invention. In other embodiments, thegarbage collection look-up table 500 may just record a serial number ofthe aforementioned each block and the value of importance information ofthe aforementioned each block, and the value of importance informationmay be recorded in different ways. As long as the contents or datarecorded by the garbage collection look-up table 500 may reflect thepriority of performing the garbage collection operation on theaforementioned each block, the way of recording may be presented indifferent ways.

In an embodiment of the present invention, the aforementioned garbagecollection operation is performed in a process of a background scanbeing performed on the flash memory module 120. That is, the flashmemory controller 110 may perform the garbage collection operation,periodically, or determine whether to begin the garbage collectionaccording to a schedule. When the flash memory controller 110 determinesto perform the garbage collection operation, the flash memory controller110 may refer to the garbage collection look-up table 500 shown in FIG.5 to determine which block(s) should be selected for preferentiallyperforming the garbage collection operation. It should be noted that,the garbage collection operation may be triggered by other mechanisms,for example, the garbage collection operation may be triggered when anumber of available blocks (blank blocks) within the flash memory module120 is not enough. Since the garbage collection operation in thisembodiment is performed during the background scan, the priorities ofperforming the garbage collection operation on the blocks may only bedetermined only by referring the garbage collection look-up table 500without considering other factors such as shortage of available blocks.

FIG. 6 is a flowchart illustrating the method for managing a flashmemory module according to an embodiment of the present invention.Referring to descriptions disclosed in FIGS. 1-5, a flow of FIG. 6 maybe described as follows:

Step 600: The flow start.

Step 602: Build garbage collection look-up table, where the garbagecollection look-up table records a plurality sets of importanceinformation respectively corresponding to a plurality of blocks.

Step 604: When a memory controller is going to perform a garbagecollection operation on the flash memory module, the memory controllerrefers to the garbage collection look-up table to select a specificblock that has a top priority of the garbage collection operation, andperforms the garbage collection operation starting from the specificblock.

Briefly summarized, regarding the method for managing a flash memorymodule and associated flash memory controller, through building agarbage collection look-up table, a priority of a garbage collectionoperation for each block is recorded as a reference for the flash memorycontroller performing the garbage collection operation. Since thegarbage collection look-up table may be dynamically refreshed during theprocess of the flash memory controller accessing the flash memorymodule, the garbage collection look-up table can indeed reflect correctpriorities to make the garbage collection operation be performed moreefficiently.

Those skilled in the art will readily observe that numerousmodifications and alterations of the device and method may be made whileretaining the teachings of the invention. Accordingly, the abovedisclosure should be construed as limited only by the metes and boundsof the appended claims.

What is claimed is:
 1. A method for managing a flash memory module,wherein the flash memory module comprises a plurality of blocks, and themethod comprises: building a garbage collection look-up table, whereinthe garbage collection look-up table records a plurality of sets ofimportance information respectively corresponding to the plurality ofblocks, and each set of importance information is used to represent apriority of performing a garbage collection operation on a correspondingblock; and when performing the garbage collection operation of the flashmemory module is required, referring to the garbage collection look-uptable to select a specific block that has a top priority of the garbagecollection operation, and performing the garbage collection operationstarting from the specific block.
 2. The method of claim 1, wherein thestep of building the garbage collection look-up table comprises:referring to at least two of a wear-leveling requirement data table, aread reclaim requirement data table and a read refresh requirement datatable, to build the garbage collection look-up table.
 3. The method ofclaim 2, wherein the step of building the garbage collection look-uptable comprises: referring to each of the wear-leveling requirement datatable, the read reclaim requirement data table and the read refreshrequirement data table, to build the garbage collection look-up table.4. The method of claim 3, wherein a set of importance information ofeach block within the garbage collection look-up table is determinedaccording to whether said each block appears in one or more of thewear-leveling requirement data table, the read reclaim requirement datatable and the read refresh requirement data table.
 5. The method ofclaim 4, wherein the wear-leveling requirement data table, the readreclaim requirement data table and the read refresh requirement datatable have corresponding weightings, respectively, and the set ofimportance information of said each block within the garbage collectionlook-up table is determined according to whether said each block appearsin one or more of the wear-leveling requirement data table, the readreclaim requirement data table and the read refresh requirement datatable and according to the corresponding weightings.
 6. The method ofclaim 5, wherein a weighting of the wear-leveling requirement data tableis greater than weightings of the read reclaim requirement data tableand the read refresh requirement data table.
 7. The method of claim 3,wherein the wear-leveling requirement data table records one or moreblocks, each having an erase count greater than a first threshold, andrecords erase counts thereof; the read reclaim requirement data tablerecords one or more blocks, each having a bit error count greater than asecond threshold, and records bit error counts thereof; and the readrefresh requirement data table records one or more blocks, each having aread count greater than a third threshold, and records read countsthereof.
 8. The method of claim 7, wherein the step of referring to thegarbage collection look-up table to select the specific block that hasthe top priority of the garbage collection operation comprises: when twoor more blocks have same importance information, referring to the erasecounts of the one or more blocks recorded by the wear-levelingrequirement data table, or referring to the bit error counts of the oneor more blocks recorded by the read reclaim requirement data table, orreferring to the read counts of the one or more blocks recorded by theread refresh requirement data table, to select the specific block thathas the top priority of the garbage collection operation.
 9. The methodof claim 1, wherein the step of referring to the garbage collectionlook-up table to select the specific block that has the top priority ofthe garbage collection operation and the step of performing the garbagecollection operation starting from the specific block are performed in aprocess of a flash memory controller performing a background scan on theflash memory module.
 10. A flash memory controller, wherein the flashmemory controller is arranged to access a flash memory module, the flashmemory module comprises a plurality of blocks, and the flash memorycontroller comprises: a read only memory, arranged to store a programcode; and a microprocessor, arranged to execute the program code tocontrol access to the flash memory module; wherein the microprocessorbuilds a garbage collection look-up table, wherein the garbagecollection look-up table records a plurality of sets of importanceinformation respectively corresponding to the plurality of blocks, andeach set of importance information is used to represent a priority ofperforming a garbage collection operation on a corresponding block; andwhen performing the garbage collection operation of the flash memorymodule is required, the microprocessor refers to the garbage collectionlook-up table to select a specific block that has a top priority of thegarbage collection operation, and performs the garbage collectionoperation starting from the specific block.
 11. The flash memorycontroller of claim 10, wherein the microprocessor refers to at leasttwo of a wear-leveling requirement data table, a read reclaimrequirement data table and a read refresh requirement data table, tobuild the garbage collection look-up table.
 12. The flash memorycontroller of claim 11, wherein the microprocessor refers to each of thewear-leveling requirement data table, the read reclaim requirement datatable and the read refresh requirement data table, to build the garbagecollection look-up table.
 13. The flash memory controller of claim 12,wherein a set of importance information of each block within the garbagecollection look-up table is determined according to whether said eachblock appears in one or more of the wear-leveling requirement datatable, the read reclaim requirement data table and the read refreshrequirement data table.
 14. The flash memory controller of claim 13,wherein the wear-leveling requirement data table, the read reclaimrequirement data table and the read refresh requirement data table havecorresponding weightings, respectively, and the set of importanceinformation of said each block within the garbage collection look-uptable is determined according to whether said each block appears in oneor more of the wear-leveling requirement data table, the read reclaimrequirement data table and the read refresh requirement data table andaccording to the corresponding weightings.
 15. The flash memorycontroller of claim 14, wherein a weighting of the wear-levelingrequirement data table is greater than weightings of the read reclaimrequirement data table and the read refresh requirement data table. 16.The flash memory controller of claim 12, wherein the wear-levelingrequirement data table records one or more blocks, each having an erasecount greater than a first threshold, and records erase counts thereof;the read reclaim requirement data table records one or more blocks, eachhaving a bit error count greater than a second threshold, and recordsbit error counts thereof; and the read refresh requirement data tablerecords one or more blocks, each having a read count greater than athird threshold, and records read counts thereof.
 17. The flash memorycontroller of claim 16, wherein when two or more blocks have sameimportance information, the microprocessor refers to the erase counts ofthe one or more blocks recorded by the wear-leveling requirement datatable, or refers to the bit error counts of the one or more blocksrecorded by the read reclaim requirement data table, or refers to theread counts of the one or more blocks recorded by the read refreshrequirement data table, to select the specific block that has the toppriority of the garbage collection operation.
 18. The flash memorycontroller of claim 10, wherein in a process of performing a backgroundscan on the flash memory module, the microprocessor refers to thegarbage collection look-up table to select the specific block that hasthe top priority of the garbage collection operation, and performs thegarbage collection operation starting from the specific block.
 19. Anelectronic device, comprising: a flash memory module, comprising aplurality of blocks; and a flash memory controller, arranged to accessthe flash memory module; wherein the flash memory controller builds agarbage collection look-up table, wherein the garbage collection look-uptable records a plurality of sets of importance information respectivelycorresponding to the plurality of blocks, and each set of importanceinformation is used to represent a priority of performing a garbagecollection operation on a corresponding block; and when performing thegarbage collection operation is required, the flash memory controllerrefers to the garbage collection look-up table to select a specificblock that has a top priority of the garbage collection operation, andperforms the garbage collection operation starting from the specificblock.
 20. The electronic device of claim 19, wherein the flash memorycontroller refers to each of the wear-leveling requirement data table,the read reclaim requirement data table and the read refresh requirementdata table, to build the garbage collection look-up table.